<?
header("Content-type:text/html;charset=utf-8");
include("../com.inc.php");
if(!$fid=$_SESSION['memberID']){exit("<script>window.location='client/index.html'</script>");}
//写入数据库
if(!$topic = htmlspecialchars($_POST['title'],ENT_COMPAT,'UTF-8')){echo "标题不能为空";exit;}

// if(!$pos = strpos($_REQUEST['detailInfo'],"<img src=")){echo "请上传至少一张图片 格式为jpg|gif|png";exit;}
$text = $_POST['detailInfo'];
if(($leng=strlen($text))<2){
//echo "<script>alert('正文不能少于50字!');parent.window.location='http://mx.12301.cc/yb/member.php';</script>"; 
echo '正文不能少于50字!';
exit;}
$playtime = date("Y-m-d H:i:s");
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
preg_match_all($pattern,$text,$match);
$pic=$match[1][0];
if(!$pic){
    //echo "<script>alert('至少包含一张图片!');parent.window.location='http://mx.12301.cc/yb/member.php';</script>";//
    echo '至少包含一张图片';
    exit;
}

if($_REQUEST['id']){
    $id=$_REQUEST['id'];
    $sql = "UPDATE uu_blog set topic='$topic',content='$text',pic='$pic' where id='$id'";
    if($GLOBALS['le']->query($sql))echo "修改成功";
}else{  
    $sql = "INSERT into uu_blog (topic,playtime,pic,fid,content) values('$topic','$playtime','$pic','$fid','$text')";
    if($GLOBALS['le']->query($sql))echo "发布成功";  
}

//跳回游记页面
echo '<script language="javascript">';
echo 'window.location.href="/client/iframe/gonglue.html"';
echo '</script>';
?>
